<template>
	<view class="mine-container full-container" :style="{height: `${windowHeight}px`}">
		<!--顶部个人信息栏-->
		<view class="header-section">
			<view class="flex padding justify-between">
				<view class="flex align-center">
					<view v-if="!avatar" class="cu-avatar xl round bg-white">
						<view class="iconfont icon-people text-gray icon"></view>
					</view>
					<image v-if="avatar" @click="handleToAvatar" :src="avatar" class="cu-avatar xl round"
						mode="widthFix">
					</image>
					<view v-if="!name" @click="handleToLogin" class="login-tip">
						点击登录
					</view>
					<view v-if="name" class="user-info">
						<view class="u_title">
							用户名：{{ name }}
						</view>
						<view class="flex" v-if="invitationCode">
							邀请码：{{invitationCode}}
							<up-copy :content="invitationCode" style="margin-left: 10rpx;">
								<uni-icons custom-prefix="iconfont" type="icon-copy" color="#fff" size="18"></uni-icons>
							</up-copy>
						</view>
					</view>
				</view>
				<view @click="handleToInfo" class="flex align-center">
					<text style="width: 150rpx;">个人信息</text>
					<view class="iconfont icon-right"></view>
				</view>
			</view>
		</view>

		<view class="content-section">
			<view class="mine-actions grid col-3 text-center">
				<!-- <view class="action-item" @click="$tab.navigateTo('/pages_mine/pages/wallet/index')">
					<view class="iconfont icon-wodeqianbao text-pink icon"></view>
					<text class="text">我的钱包</text>
				</view> -->
				<view class="action-item" @click="$tab.navigateTo('/pages_mine/pages/group/index')">
					<view class="iconfont icon-wodetuandui text-pink icon"></view>
					<text class="text">我的团队</text>
				</view>
				<view class="action-item" @click="$tab.navigateTo('/pages_mine/pages/property/index')">
					<view class="iconfont icon-wodezichan text-cyan icon"></view>
					<text class="text">我的资产</text>
				</view>
				<view class="action-item" @click="$tab.navigateTo('/pages_mine/pages/profit/index')">
					<view class="iconfont icon-chongzhi text-orange icon"></view>
					<text class="text">我的收益</text>
				</view>
				<!-- <view class="action-item" @click="$tab.navigateTo('/pages_mine/pages/recharge/index')">
					<view class="iconfont icon-chongzhi text-mauve icon"></view>
					<text class="text">我要充值</text>
				</view>
				<view class="action-item" @click="$tab.navigateTo('/pages_mine/pages/withdrawal/index')">
					<view class="iconfont icon-tixian text-green icon"></view>
					<text class="text">我要提现</text>
				</view> -->
				<view class="action-item" @click="$tab.navigateTo('/pages/account/index')">
					<view class="iconfont icon-shoukuanxinxiguanli text-yellow icon"></view>
					<text class="text">收款账号</text>
				</view>
				<view class="action-item" @click="$tab.navigateTo('/pages_mine/pages/google/index')">
					<view class="iconfont icon-google_plus text-brown icon"></view>
					<text class="text">安全中心</text>
				</view>
				<!-- <view class="action-item" @click="handleBuilding">
					<view class="iconfont icon-zaixiankefu1 text-orange icon"></view>
					<text class="text">在线客服</text>
				</view> -->
				<view class="action-item" @click="$tab.navigateTo('/pages_mine/pages/setting/index')">
					<view class="iconfont icon-setting text-purple icon"></view>
					<text class="text">系统设置</text>
				</view>

			</view>

			<view class="menu-list">
				<!-- 				<view class="list-cell list-cell-arrow" @click="$tab.navigateTo('/pages/account/index')">
					<view class="menu-item-box">
						<view class="iconfont icon-shoukuanxinxiguanli menu-icon"></view>
						<view>收款信息</view>
					</view>
				</view> -->

				<!-- <view class="list-cell list-cell-arrow" @click="$tab.navigateTo('/pages_mine/pages/group/index')">
					<view class="menu-item-box">
						<view class="iconfont icon-wodetuandui menu-icon"></view>
						<view>我的团队</view>
					</view>
				</view> -->

				<!-- <view class="list-cell list-cell-arrow" @click="$tab.navigateTo('/pages_mine/pages/google/index')">
					<view class="menu-item-box">
						<view class="iconfont icon-google_plus menu-icon"></view>
						<view>谷歌验证码</view>
					</view>
				</view> -->

				<!-- <view class="list-cell list-cell-arrow" @click="handleBuilding">
					<view class="menu-item-box">
						<view class="iconfont icon-zaixiankefu1 menu-icon"></view>
						<view>在线客服</view>
					</view>
				</view> -->

				<!-- 	<view class="list-cell list-cell-arrow" @click="handleBuilding">
					<view class="menu-item-box">
						<view class="iconfont icon-yaoqingyoujiang menu-icon"></view>
						<view>邀请有奖</view>
					</view>
				</view> -->

				<!-- <view class="list-cell list-cell-arrow" @click="handleToSetting">
					<view class="menu-item-box">
						<view class="iconfont icon-setting menu-icon"></view>
						<view>系统设置</view>
					</view>
				</view> -->
			</view>

		</view>

		<view class="cu-list menu">
			<view class="cu-item item-box">
				<view class="content text-center" @click="handleLogout">
					<text class="text-black">退出登录</text>
				</view>
			</view>
		</view>

		<uni-popup ref="popup" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="退出" title="通知" content="确定注销并退出系统吗"
				@confirm="dialogConfirm" @close="dialogClose">
			</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script setup>
	import storage from '@/utils/storage'
	import store from '@/store'
	import {
		ref,computed
	} from "vue";
	import config from '@/config.js'
	
	const name = computed(() => {
		return store?.state?.user?.name || '';
	})
	
	const invitationCode = computed(() => {
		return store?.state?.user?.invitationCode || '';
	})
	
	const version = computed(() => {
		return config?.appInfo?.version || '';
	})
	
	const avatar = computed(() => {
		return store?.state?.user?.avatar || '';
	})

	const windowHeight = ref(uni.getSystemInfoSync().windowHeight - 50);
	const popup = ref(null);

	uni.$on('refresh', () => {
		avatar.value = store.state.user.avatar;
	})

	function handleToInfo() {
		uni.navigateTo({
			url: '/pages_mine/pages/info/index'
		});
	};

	function handleToMyOrder() {
		uni.navigateTo({
			url: '/pages_mine/pages/order/index'
		});
	};

	function handleToSetting() {
		uni.navigateTo({
			url: '/pages_mine/pages/setting/index'
		});
	};

	function handleToLogin() {
		uni.reLaunch({
			url: '/pages/login'
		});
	};

	function handleToAvatar() {
		uni.navigateTo({
			url: '/pages_mine/pages/avatar/index'
		});
	};

	function handleLogout() {
		popup.value.open();
	};

	function dialogConfirm() {
		//console.log('----------------点击确认------------')
		store.dispatch('LogOut').then(() => {
			uni.reLaunch({
				url: '/pages/login'
			});
		})
	};

	function dialogClose() {
		//console.log('点击关闭')
	};

	function handleHelp() {
		uni.navigateTo({
			url: '/pages_mine/pages/help/index'
		});
	};

	function handleToRatio() {
		uni.navigateTo({
			url: '/pages_mine/pages/ratio/index'
		});
	};

	function handleJiaoLiuQun() {
		uni.showToast({
			title: 'QQ群：133713780',
			mask: false,
			icon: "none",
			duration: 3000
		});
	};

	function handleBuilding() {
		uni.showToast({
			title: '模块建设中~',
			mask: false,
			icon: "none",
			duration: 1000
		});
	}
</script>

<style lang="scss">
	page {
		background-color: #f5f6f7;
	}

	.mine-container {
		width: 100%;
		height: calc(100vh - var(--window-bottom) - var(--status-bar-height) - var(--window-top)) !important;

		.header-section {
			padding: 15px 15px 45px 15px;
			background-color: #3c9cff;
			color: white;

			.login-tip {
				font-size: 18px;
				margin-left: 10px;
			}

			.cu-avatar {
				border: 2px solid #eaeaea;

				.icon {
					font-size: 40px;
				}
			}

			.user-info {
				margin-left: 15px;

				.u_title {
					font-size: 18px;
					line-height: 30px;
				}
			}
		}

		.content-section {
			position: relative;
			top: -50px;

			.mine-actions {
				margin: 15px 15px;
				padding: 20rpx 0px;
				border-radius: 8px;
				background-color: white;

				.action-item {
					padding: 20rpx;

					.icon {
						font-size: 36px;
					}

					.text {
						display: block;
						font-size: 13px;
						margin: 8px 0px;
					}
				}
			}
		}

		.cu-list {
			flex: 1;
			margin-top: -50rpx;
			display: flex;
			flex-direction: column;
			// align-items: center;
			justify-content: flex-end;
			padding-bottom: 50rpx;
			box-sizing: border-box;
		}

		.item-box {
			background-color: #FFFFFF;
			margin: 40rpx 80rpx;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			padding: 10rpx;
			border-radius: 8rpx;
			color: #303133;
			font-size: 32rpx;
		}
	}
</style>